#include <iostream>
#include <unordered_map>
using namespace std;

unordered_map<string, int> ha;

int main()
{
	int n; cin >> n;
	
	int ret;
	while (n--)
	{
		string a, b; cin >> a >> b;
		a = a.substr(0, 2);
		
		if (a == b) continue; 
		
		ret += ha[a + b];
		ha[b + a]++;
	}
	
	cout << ret << endl;
	
	return 0;
}
